<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <link rel="stylesheet" href="/webjars/layui/2.5.5/css/layui.css">
    <script src="/webjars/jquery/3.4.1/jquery.min.js"></script>
    <style>
        body {
            padding: 20px;
        }
        button {
            margin: 20px;
        }
    </style>
</head>

<body>
    <button id="findAll" type="button" class="layui-btn">查询全部用户</button>
    <div>
        <span>ID: </span>
        <input type="text" id="userId" class="layui-input">
        <button type="submit" id="findUserById" class="layui-btn">根据ID查询用户</button>
    </div>
    <script>
        $("#findAll").click(function() {
            $.ajax({
                url: "user/find", //请求URL
                type: "GET", //请求方式
                beforeSend: function(res) {
                    //请求前的回调函数
                },
                success: function(res) {
                    //请求成功的回调函数
                    alert(res);
                },
                complete: function(res) {
                    //请求完成的回调函数
                },
                error: function(res) {
                    //请求出错的回调函数
                },
            });
        });
        $("#findUserById").click(function() {
            var userId = $("#userId").val();
            $.ajax({
                url: "user/findById/" + userId,
                type: "GET",
                success: function(res) {
                    alert(JSON.stringify(res));
                },
            });
        });
    </script>
</body>
</html>